<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        
        <!-- jquery -->
        <script src="/lianxijs/libs/jquery/jquery-1.11.1.min.js"></script>
        
        <!-- http插件 -->
        <script src="/lianxijs/libs/http/axios.min.js"></script>
        
        <!-- 弹窗插件 -->
        <link rel="stylesheet" type="text/css" href="/lianxijs/libs/sweetalert/sweetalert.css"  />
        <script src="/lianxijs/libs/sweetalert/sweetalert-dev.js"></script>
        
        <!-- 时间格式化插件 -->
        <script src="/lianxijs/libs/moment/moment.min.js"></script>   
        
        <!-- 精确计算插件 -->
        <!-- <script src="/lianxijs/libs/number-precision/index.iife.js"></script> -->
        <script src="/lianxijs/libs/number-precision/index.umd.js"></script>
        
        <!-- 带搜索的下拉框 -->
        <link rel="stylesheet" type="text/css" href="/lianxijs/libs/select2/select2.css"/>
        <script src="/lianxijs/libs/select2/select2.js"></script>
        
        <!-- base64插件（https://github.com/dankogai/js-base64） -->
        <script src="/lianxijs/libs/base64/base64.min.js"></script>
        
    </head>
    <body>
        <div>
            原始字符串：<input id="text" style="width:500px;" type="text" placeholder="请输入字符串"/>
        </div>
        <br/>
        <div>
            <input onClick="base64Encode()" type="button" value="使用插件转为base64字符串"/> <a id="aaa"></a> <br/><br/>
            <input onClick="base64Encode1()" type="button" value="使用浏览器自带功能转为blob字符串"/> <a id="bbb"></a> <br/><br/>
            <input onClick="base64Encode2()" type="button" value="使用浏览器自带功能转为base64字符串"/> <a id="ccc"></a> <br/><br/>
        </div>
    </body>
</html>
<script>
    let base64Encode = function () {
        let base64Str = "data:*;base64," + Base64.encode($("#text").val()); 
        console.log(base64Str);
        $("#aaa").attr("href", base64Str).attr("download", "使用插件转为base64字符串.txt").text("点我下载");
    };
    let base64Encode1 = function () {
        let data = $("#text").val();
        let base64Str = window.URL.createObjectURL(new Blob([data])); 
        console.log(base64Str);
        $("#bbb").attr("href", base64Str).attr("download", "使用浏览器自带功能转为blob字符串.txt").text("点我下载");
    };
    let base64Encode2 = function () {
        let data = $("#text").val();
        let reader = new FileReader();
        reader.readAsDataURL(new Blob([data]));
        reader.onload = function (e) {
            console.log(e.target.result);
            $("#ccc").attr("href", e.target.result).attr("download", "使用浏览器自带功能转为base64字符串.txt").text("点我下载");
        };        
    };
</script>